define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'general/storejoin/index',
                    add_url: 'general/storejoin/add',
                    edit_url: 'general/storejoin/edit',
                    del_url: 'general/storejoin/del',
                    multi_url: 'general/storejoin/multi',
                    table: 'storejoin',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                       /* {field: 'user_id', title: __('User_id')},*/
                        {field: 'user_name', title: __('User_name')},
                        {field: 'store_name', title: __('Store_name')},
                       /* {field: 'company', title: __('Company')},*/
                        {field: 'store_type', title: __('Store_type'), visible:false,searchList: {"1":__('Store_type 1'),"2":__('Store_type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'store_type_text',operate:false, title: __('Store_type'), searchList: {"1":__('Store_type 1'),"2":__('Store_type 2')}, formatter: Table.api.formatter.normal},

                        {field: 'store_status', title: __('Store_status'),  visible:false,searchList: {"1":__('Store_status 1'),"2":__('Store_status 2'),"3":__('Store_status 3'),"4":__('Store_status 4'),"5":__('Store_status 5')}, formatter: Table.api.formatter.status},
                        {field: 'store_status_text',operate:false, title: __('Store_status'), searchList: {"1":__('Store_status 1'),"2":__('Store_status 2'),"3":__('Store_status 3'),"4":__('Store_status 4'),"5":__('Store_status 5')}, formatter: Table.api.formatter.status},

                        {field: 'store_reason', title: __('Store_reason')},
                    /*    {field: 'reason_is_see', title: __('Reason_is_see'), visible:false,searchList: {"1":__('Reason_is_see 1'),"2":__('Reason_is_see 2')}, formatter: Table.api.formatter.normal},
                        {field: 'reason_is_see_text', title: __('Reason_is_see'),operate:false, searchList: {"1":__('Reason_is_see 1'),"2":__('Reason_is_see 2')}, formatter: Table.api.formatter.normal},
*/

                        {field: 'store_phone', title: __('Store_phone')},
                        {field: 'mobile', title: __('Mobile')},
                       /* {field: 'is_retreat', title: __('Is_retreat'), visible:false, searchList: {"1":__('Is_retreat 1'),"2":__('Is_retreat 2'),"3":__('Is_retreat 3')}, formatter: Table.api.formatter.normal},
                        {field: 'is_retreat_text',operate:false ,title: __('Is_retreat'), searchList: {"1":__('Is_retreat 1'),"2":__('Is_retreat 2'),"3":__('Is_retreat 3')}, formatter: Table.api.formatter.normal},
*/
                        {field: 'qq', title: __('Qq')},
                        {field: 'wx', title: __('Wx')},
                        {field: 'business_licence_number', title: __('Business_licence_number'), formatter: Table.api.formatter.image},
                        {field: 'agreement', title: __('Agreement'), visible:false,searchList: {"1":__('Agreement 1'),"2":__('Agreement 2')}, formatter: Table.api.formatter.normal},
                        {field: 'agreement_text', title: __('Agreement'), operate:false,searchList: {"1":__('Agreement 1'),"2":__('Agreement 2')}, formatter: Table.api.formatter.normal},

                        {field: 'qrcode', title: __('Qrcode'), formatter: Table.api.formatter.image},
                        {field: 'store_label', title: __('Store_label'), formatter: Table.api.formatter.image},
                        {field: 'store_deposit', title: __('Store_deposit'), operate:'BETWEEN'},
                        {field: 'store_brief', title: __('Store_brief')},
                        {field: 'store_time', title: __('Store_time')},
                        {field: 'customer_phone', title: __('Customer_phone')},
                        {field: 'store_turnover', title: __('Store_turnover'), operate:'BETWEEN'},
                        {field: 'store_order_num', title: __('Store_order_num')},
                        {field: 'sell_name', title: __('Sell_name')},
                       /* {field: 'sell_pwd', title: __('Sell_pwd')},*/
                        {field: 'store_pic', title: __('Store_pic'), formatter: Table.api.formatter.image},

                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'operate', title: __('Operate'), table: table, buttons: [

                                {
                                    name: 'pass',
                                    text: '申请通过',
                                    title: '申请通过',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-xs btn-primary btn-ajax',
                                    confirm: '确认通过？',
                                    url: 'storejoin/storejoin/pass',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");//刷新当前页面的数据
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    }
                                },
                                {
                                    name: 'refuse',
                                    text: '拒绝',
                                    title: '拒绝',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'storejoin/storejoin/refuse'
                                },
                                ], events: Table.api.events.operate, formatter: Table.api.formatter.operate ,formatter: function (value, row, index) {
                                var that = $.extend({}, this);
                                var table = $(that.table).clone(true);
                              //  $(table).data("operate-edit", null);
                                $(table).data("operate-del", null);
                                if(row.store_status !=3){
                                    $(table).data("operate-pass", null);
                                    $(table).data("operate-refuse", null);
                                }

                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            }}
                    ]
                ]
            });

            

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        pass: function () {
            Controller.api.bindevent();
        },
        refuse: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});